package BiliBili;

import java.util.Scanner;

/**
 * @author zhangmin
 * @create 2022-09-20 18:30
 */
public class Main_0920_2 {
    public static void main(String[] args) {
        Scanner cin=new Scanner(System.in);
        int n=cin.nextInt();
        int[] nums=new int[n];
        for (int i = 0; i < n; i++) {
            nums[i]=cin.nextInt();
        }
        cin.nextLine();
        char[] color=cin.nextLine().toCharArray();
        long max_R=Integer.MIN_VALUE,min_R=Integer.MAX_VALUE;
        long max_B=Integer.MIN_VALUE,min_B=Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            if (color[i]=='R'){
                max_R=Math.max(nums[i],max_R);
                min_R=Math.min(nums[i],min_R);
            }else if (color[i]=='B'){
                max_B=Math.max(nums[i],max_B);
                min_B=Math.min(nums[i],min_B);
            }
        }

        long maxMul=(max_B==Integer.MIN_VALUE||max_R==Integer.MIN_VALUE)?Integer.MIN_VALUE:max_B*max_R;
        long minMul=(min_B==Integer.MAX_VALUE||min_R==Integer.MAX_VALUE)?Integer.MIN_VALUE:min_B*min_R;

        System.out.println(Math.max(maxMul,minMul));
    }
}
